<?php
require_once "common.php";
require_once __DIR__ . '/../vendor/autoload.php';
use phpspider\core\phpspider;
use  phpspider\core\selector;
$html =<<<STR
    <div id="demo">
        <span class="tt">bbb</span>
        <span>ccc</span>
        <p rel="pnode">ddd</p>
    </div>
STR;


// 获取id为demo的div内容
$data = selector::select($html, "//div[@id='demo']");
p($data);
// 获取class为tt的span内容
$data = selector::select($html, "//span[@class='tt']");
p($data);
// 获取rel为pnode的p内容
$data = selector::select($html, "//p[@rel='pnode']");
p($data);



$html =<<<STR
    <div id="demo1">
        99999
    </div>
    <div id="demo2">
        88888
    </div>
STR;

// 查找id属性中包含demo关键字的页面元素
// 这里能获取id为demo1和demo2的内容
$data = selector::select($html, "//div[contains(@id,'demo')]");
p($data);



$html =<<<STR
    <div data-id="222">3333</div>   
STR;

// 获取 td 的 data-value 属性
$data = selector::select($html, "//div[@data-id='222']");
p($data); die;

